<?php
    class IndexController extends Main_Controller_Action
    {
        private $_arrParam;
    	
        public function init() {
            $this->loadTemplates();
            $this->_arrParam = $this->_request->getParams();
        }
        
        public function indexAction() {
            $this->view->headTitle('Lễ vu quy Hoàng - Mai');
        }
        
        public function aboutAction(){
            $this->view->headTitle('Về chúng tôi');
        }
        
        public function albumAction(){
            $this->view->headTitle('Album');
            define('PATH', PUBLIC_PATH.'/files/gallery/images');
            $files = array();
            $dir = opendir(PATH);
            while ($f = readdir($dir)){
                if (preg_match("/\.jpg|\.gif|\.png/i", $f))
                    array_push($files,$f);
            }
            closedir($dir);
            
            if(!empty($files)){
                $this->view->data = $files;
            }
        }
        
        public function timeAction(){
            $this->view->headTitle('Thời gian tổ chức');
        }
        public function commentAction(){
            $this->view->headTitle('Chúc mừng hạnh phúc');
            $captcha = new Zend_Captcha_Image();
            $captcha->setTimeout('300')               
                 ->setWordLen('4')
                 ->setHeight('40')        
                 ->setWidth('80')                           
                 ->setImgDir(APPLICATION_PATH . '/../public/img/captcha/')
                 ->setImgUrl('/hoangmai/public/img/captcha/')
                 ->setFont('public/fonts/tunga.ttf')
                 ->setFontSize('20');                   
            $captcha->generate(); 
            $this->view->captcha = $captcha->render($this->view);  
            $this->view->captchaID = $captcha->getId();
            $captchaSession = new Zend_Session_Namespace('Zend_Form_Captcha_' . $captcha->getId());
            $captchaSession->word = $captcha->getWord();
            $this->view->word = $captchaSession->word;
            
            $congratulations = new Default_Model_Congratulations();
            $list = $congratulations->listCongratulations(1);
            $adapter = new Zend_Paginator_Adapter_DbSelect($list);
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(4);
            $paginator->setPageRange(5);
            $current = $this->_request->getParam('page', 1);
            $paginator->setCurrentPageNumber($current); 
            $this->view->data = $paginator;
        }
        public function addAction(){
            $this->_helper->layout()->disableLayout();
            $content = $this->_arrParam['nd'];
            $fullname = $this->_arrParam['fullname'];
            $congratulations = new Default_Model_Congratulations();
            $data = array(
                          'fullname' => $fullname,
                          'content' => $content,
                          'create_time' => date("Y-m-d H:i"),
                          'status' => 1
                        );
            $congratulations->add($data);
            $list = $congratulations->listCongratulations(1);
            $adapter = new Zend_Paginator_Adapter_DbSelect($list);
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(4);
            $paginator->setPageRange(5);
            $current = $this->_request->getParam('page', 1);
            $paginator->setCurrentPageNumber($current);            
            $this->view->data = $paginator;
        }
    }
